package lexer;

import symbols.Position;

import java.io.*;

public class Reader {

    private final BufferedInputStream in;
    private final File file;

    private int line = 0;
    private int row = 0;


    public Reader(final File file) throws FileNotFoundException {
        this.file = file;
        this.in = new BufferedInputStream(new FileInputStream(this.file));
    }


    public int nextChar() throws IOException {
        final int nextChar = in.read();
        if (nextChar == '\n') {
            this.row = 0;
            this.line++;
        } else {
            this.row++;
        }
        return nextChar;
    }

    public Position getPosition() {
        return new Position(this.line, this.row, this.file.getAbsolutePath());
    }


}
